﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Puzzle3;
using Puzzle;

namespace Puzzle3
{
    class Program
    {
        static void Main(string[] args)
        {
            string dest = "C:\\Users\\Icarus\\Desktop\\Board1.txt";
            File.AppendAllText(dest, "if(>90) onlyCenter(700,2) onlyCorner(100) OnlyEdge(200) ELSE mutate(1000)\n");
            Puzzle.Population pops = new Puzzle.Population();
            pops.readInSolved();
            pops.readInRandom();
           
            int i = 0;
            //for (int i = 0; i < 100000; i++)
            while (true)
            {
                pops.doublePopulation();
                pops.evalFitness();
                //pops.mutate(Population.mutateMode.conserveEdges,3000);

                if ((pops.boards[4].approxTilesArranged()/10) > 90)
                {
                    pops.mutateOnlyCenter(700, 2);
                    pops.mutateOnlyCorner(100);
                    pops.mutateOnlyEdge(200);
                }
                else
                {
                    pops.mutate(Population.mutateMode.conserveEdges, 1000);
                }

                pops.selectPopulation();

                if (i % 100 == 0)
                {
                    pops.rotateAllEdgesAndCornersCorrectly();
                    pops.evalFitness();
                    Console.Clear();
                    Console.WriteLine("Iter:" + i.ToString());
                    //pops.displayAllBoardsFitness();
                    pops.writeFitnessToFile(i, dest);

                }


                i++;
            }
        }


    }
}
